package com.gitee.Jmysy.binlog4j.springboot.starter.example.handler;

import com.gitee.Jmysy.binlog4j.core.BinlogEvent;
import com.gitee.Jmysy.binlog4j.core.IBinlogEventHandler;
import com.gitee.Jmysy.binlog4j.springboot.starter.annotation.BinlogSubscriber;

@BinlogSubscriber(clientName = "master")
public class BinlogPositionEventHandler implements IBinlogEventHandler {

    private long time = 0;

    private long count = 0;

    @Override
    public void onInsert(BinlogEvent event) {
        System.out.println("插入数据:" + event.getData());
    }

    @Override
    public void onUpdate(BinlogEvent event)  {
        System.out.println("修改数据:" + event.getData());
    }

    @Override
    public void onDelete(BinlogEvent event) {

        if(time == 0) {
            time = System.currentTimeMillis();
        }

        System.err.println("execution time:" + (System.currentTimeMillis() - time) + " - index:" + count++);

    }

    @Override
    public boolean isHandle(String database, String table) {
        return true;
    }
}
